<template>

    <!-- 添加或修改对话框 -->
    <lam-dialog title="修改订单收件信息" :visible.sync="open" width="680px" append-to-body @close="cancel">
      <el-form :ref="formRef" :model="form" :rules="rules" label-width="100px" :disabled="formDisabled">
        <el-row>
          <el-col :span="12">
            <el-form-item label="收货人" prop="receiver">
              <el-input v-model="form.receiver" clearable placeholder="" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="省" prop="provinceId">
              <lam-dict-select v-model="form.provinceId" dictCode="provinceData" dictType="tableDict" placeholder="" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="城市" prop="cityId">
              <lam-dict-select v-model="form.cityId" :dictCode="cityDataCode" dictType="tableDict" placeholder="" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="区/县" prop="areaId">
              <lam-dict-select v-model="form.areaId" :dictCode="areaDataCode" dictType="tableDict" placeholder="" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="邮编" prop="postCode">
              <el-input v-model="form.postCode" clearable placeholder="" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="详情地址" prop="addr">
              <el-input v-model="form.addr" type="textarea" autosize placeholder="" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="收货人手机" prop="mobile">
              <el-input v-model="form.mobile" clearable placeholder="" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" :loading="loading">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </lam-dialog>

</template>

<script>
import { EditMixin } from '@/components/mixins/EditMixin';

export default {
  name: "EditOrderAddr",
  mixins:[EditMixin],
  data() {
    return {
      url: {
        base: '/mall/orderAddr/'
      },
      // 表单校验
      rules: {
        receiver: [{ required: true, message: "收货人不能为空", trigger: "blur" }],
        provinceId: [{ required: true, message: "省不能为空", trigger: "blur" }],
        cityId: [{ required: true, message: "城市不能为空", trigger: "blur" }],
        areaId: [{ required: true, message: "区/县不能为空", trigger: "blur" }],
        addr: [{ required: true, message: "详情地址不能为空", trigger: "blur" }],
        mobile: [{ required: true, message: "收货人手机不能为空", trigger: "blur" }],
      },
    };
  },
  computed:{
    cityDataCode(){
      return 'cityData:'+this.form.provinceId;
    },
    areaDataCode(){
      return 'areaData:'+this.form.cityId;
    },
  },
  created() {
  },
  methods: {
    // 表单重置
    reset() {
      this.form = {
        userId: null,
        receiver: null,
        provinceId: "0",
        cityId: "0",
        areaId: "0",
        postCode: null,
        addr: null,
        mobile: null,
      };
    },

    /** 提交按钮 */
    submitForm(){
      this.$refs[this.formRef].validate(valid => {
        if (valid) {
          this.loading = true;
          this.$httpPut(this.url.base, this.form).then(res => {
            this.msgSuccess("修改成功！");
            this.open = false;
            this.$emit('ok', res.data);
          }).catch(()=>{}).finally(()=>{
            this.loading = false;
          });
        }
      });
    }

  }
};
</script>
